package com.hundsun.s3.mrs.core.task;

import java.util.UUID;

import com.hundsun.s3.mrs.core.IParamsIn;
import com.hundsun.s3.mrs.core.IParamsOut;
import com.hundsun.s3.mrs.core.message.Message;
import com.hundsun.s3.mrs.core.talker.Talker;

/**
 * 任务接口，所有的任务都必须实现此接口
 * @author chenji23607
 *
 */
public abstract class Task implements IParamsIn, Runnable {

	/**
	 * 业务回调函数
	 */
	private IParamsOut callback;
	
	private String taskId = UUID.randomUUID().toString();
	
	/**
	 * 消息的创建者
	 */
	protected Talker creater;
	
	public Task() {
		super();
	}

	public Task(Talker creater) {
		this.creater = creater;
	}
	
	public Task(IParamsOut callback, Talker creater) {
		super();
		this.callback = callback;
		this.creater = creater;
	}
	
	
	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}
	/**
	 * 判断是否是自己发出来的任务
	 * @param senderId Message中的senderId
	 * @return
	 */
	public boolean isMyJob(String senderId) {
		return this.creater.getId().equals(senderId);
	}
	
	
	/**
	 * 获取任务的id
	 * @return
	 */
	public String getTaskId(){
		return taskId;
	}

	public Talker getCreater() {
		return creater;
	}

	public void setCreater(Talker creater) {
		this.creater = creater;
	}

	public IParamsOut getCallback() {
		return callback;
	}
	public void setCallback(IParamsOut callback) {
		this.callback = callback;
	}
	public abstract Message getMessage();
	
	/**
	 * 执行任务
	 */
	public abstract void exec();
	
	/**
	 * 将自己(任务)放入该存放的数据结构中，并唤醒相应的处理线程
	 */
	public abstract void up();

}


